package serv

import (
	"context"
	"net/http"
	"time"

	"code.bydev.io/cht/customer/kyc_admin_service/internal/pkg/biz"
	"code.bydev.io/cht/customer/kyc_admin_service/internal/pkg/biz/controllers/imgctl"
	"git.bybit.com/svc/go/pkg/bzap"
)

type imgservice struct {
	env *biz.Environment
}

func NewImgService(env *biz.Environment) *imgservice {
	return &imgservice{env: env}
}

func (s *imgservice) DownloadHandler(w http.ResponseWriter, r *http.Request) {
	var err error
	h := s.env.CreateHandlerWithTimeout(context.Background(), "DownloadHandler", 5*time.Second)
	defer h.Dispose()
	defer func() {
		if err != nil {
			bzap.LogError(h.Logger(), "DownloadHandler", err)
		}
	}()

	imgctl.New(h).DownloadHandler(h.Context(), w, r)
}
